/* 分类 */
import Mock from 'mockjs'
function param2Obj(url) {
  const search = url.split('?')[1]
  if (!search) {
    return {}
  }
  return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
}

let cateList = [
  {
    cat_id: 1,
    cat_name: '大家电',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 3,
        cat_name: '电视',
        cat_pid: 1,
        cat_level: 1,
        cat_deleted: false,
        children: [
          {
            cat_id: 6,
            cat_name: '曲面电视',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 7,
            cat_name: '海信',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 8,
            cat_name: '夏普',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 9,
            cat_name: '创维',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 10,
            cat_name: 'TCL',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 11,
            cat_name: 'PPTV',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 12,
            cat_name: '小米',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 13,
            cat_name: '长虹',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 14,
            cat_name: '康佳',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 15,
            cat_name: '三星',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 16,
            cat_name: '飞利浦',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 17,
            cat_name: '索尼',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 18,
            cat_name: '先锋',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 19,
            cat_name: '家庭影院',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 20,
            cat_name: '音响',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 21,
            cat_name: '盒子',
            cat_pid: 3,
            cat_level: 2,
            cat_deleted: false,
          },
        ],
      },
      {
        cat_id: 4,
        cat_name: '空调',
        cat_pid: 1,
        cat_level: 1,
        cat_deleted: false,
        children: [
          {
            cat_id: 23,
            cat_name: '变频空调',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 24,
            cat_name: '立柜空调',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 25,
            cat_name: '挂壁空调',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 27,
            cat_name: '中央空调',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 28,
            cat_name: '移动空调',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 29,
            cat_name: '海尔',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 30,
            cat_name: '三菱重工',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 31,
            cat_name: '志高',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 32,
            cat_name: '奥克斯',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 33,
            cat_name: '长虹',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 34,
            cat_name: '科龙',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 35,
            cat_name: '海信',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 36,
            cat_name: '惠而浦',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 37,
            cat_name: '空调清洗',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 38,
            cat_name: '空调维修',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 39,
            cat_name: '空调安装',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
          {
            cat_id: 40,
            cat_name: '空调回收',
            cat_pid: 4,
            cat_level: 2,
            cat_deleted: false,
          },
        ],
      },
      {
        cat_id: 26,
        cat_name: '洗衣机',
        cat_pid: 1,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 45,
        cat_name: '冰箱',
        cat_pid: 1,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 52,
    cat_name: '热门推荐',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 64,
        cat_name: '圣诞狂欢',
        cat_pid: 52,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 70,
    cat_name: '海外购',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 75,
        cat_name: '国际名牌',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 93,
        cat_name: '母婴儿童',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 96,
        cat_name: '美妆',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 113,
        cat_name: '个护',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 115,
        cat_name: '营养保健',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 128,
        cat_name: '食品',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 133,
        cat_name: '数码家电',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 151,
        cat_name: '服饰箱包',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 157,
        cat_name: '家居日用',
        cat_pid: 70,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 172,
    cat_name: '苏宁房产',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 173,
        cat_name: '苏宁房产',
        cat_pid: 172,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 174,
    cat_name: '手机相机',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 178,
        cat_name: '大牌推荐',
        cat_pid: 174,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 185,
        cat_name: '搞机达人',
        cat_pid: 174,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 199,
        cat_name: '手机配件',
        cat_pid: 174,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 207,
        cat_name: '手机服务',
        cat_pid: 174,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 211,
        cat_name: '运营商',
        cat_pid: 174,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 223,
        cat_name: '摄影摄像',
        cat_pid: 174,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 246,
        cat_name: '相机配件',
        cat_pid: 174,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 270,
    cat_name: '电脑办公',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 273,
        cat_name: '电脑整机',
        cat_pid: 270,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 283,
        cat_name: '电脑外设',
        cat_pid: 270,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 290,
        cat_name: 'DIY硬件',
        cat_pid: 270,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 298,
        cat_name: '网络设备',
        cat_pid: 270,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 308,
        cat_name: '办公设备',
        cat_pid: 270,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 315,
        cat_name: '文具用品',
        cat_pid: 270,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 320,
    cat_name: '厨卫电器',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 325,
        cat_name: '卫浴电器',
        cat_pid: 320,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 332,
        cat_name: '厨房大电',
        cat_pid: 320,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 342,
        cat_name: '净水设备',
        cat_pid: 320,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 351,
    cat_name: '食品酒水',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 356,
        cat_name: '中外名酒',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 360,
        cat_name: '牛奶冲调',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 369,
        cat_name: '生鲜蔬果',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 377,
        cat_name: '休闲食品',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 383,
        cat_name: '粮油干货',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 394,
        cat_name: '进口食品',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 401,
        cat_name: '方便速食',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 403,
        cat_name: '厨房调料',
        cat_pid: 351,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 406,
    cat_name: '居家生活',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 411,
        cat_name: '生活用纸',
        cat_pid: 406,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 419,
        cat_name: '家庭清洁',
        cat_pid: 406,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 427,
        cat_name: '生活日用',
        cat_pid: 406,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 439,
        cat_name: '家纺布艺',
        cat_pid: 406,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 447,
        cat_name: '宠物生活',
        cat_pid: 406,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 453,
    cat_name: '厨房电器',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 458,
        cat_name: '中式厨房',
        cat_pid: 453,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 473,
        cat_name: '西式厨房',
        cat_pid: 453,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 483,
    cat_name: '生活电器',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 487,
        cat_name: '环境电器',
        cat_pid: 483,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 505,
        cat_name: '家居电器',
        cat_pid: 483,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 513,
    cat_name: '个护健康',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 523,
        cat_name: '理容造型',
        cat_pid: 513,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 526,
        cat_name: '口腔护理',
        cat_pid: 513,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 528,
        cat_name: '健康电器',
        cat_pid: 513,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 550,
    cat_name: '烹饪厨具',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 553,
        cat_name: '锅具',
        cat_pid: 550,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 572,
        cat_name: '刀剪菜板',
        cat_pid: 550,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 577,
        cat_name: '水具酒具',
        cat_pid: 550,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 580,
    cat_name: '家装建材',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 589,
        cat_name: '灯具灯饰',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 599,
        cat_name: '厨房卫浴',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 616,
        cat_name: '五金电工',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 638,
        cat_name: '墙地面',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 645,
        cat_name: '卧室家具',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 659,
        cat_name: '客厅家具',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 669,
        cat_name: '书房办公',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 678,
        cat_name: '餐厅门厅',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 686,
        cat_name: '定制装修',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 696,
        cat_name: '品牌墙',
        cat_pid: 580,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 710,
    cat_name: '奶粉尿裤',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 719,
        cat_name: '孕婴奶粉',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 721,
        cat_name: '尿裤湿巾',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 730,
        cat_name: '营养辅食',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 740,
        cat_name: '洗护用品',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 760,
        cat_name: '喂养用品',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 777,
        cat_name: '儿童玩具',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 787,
        cat_name: '童车童床',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 801,
        cat_name: '妈妈专区',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 818,
        cat_name: '品牌墙',
        cat_pid: 710,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 847,
    cat_name: '男装',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 849,
        cat_name: '精选',
        cat_pid: 847,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 863,
        cat_name: '外套',
        cat_pid: 847,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 871,
        cat_name: '男士内搭',
        cat_pid: 847,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 872,
        cat_name: '男士裤装',
        cat_pid: 847,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 873,
        cat_name: '品牌墙',
        cat_pid: 847,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 892,
    cat_name: '男鞋',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 897,
        cat_name: '时尚男鞋',
        cat_pid: 892,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 901,
        cat_name: '品牌墙',
        cat_pid: 892,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 904,
    cat_name: '女装',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 906,
        cat_name: '精选',
        cat_pid: 904,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 912,
        cat_name: '潮流女装',
        cat_pid: 904,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 927,
        cat_name: '品牌墙',
        cat_pid: 904,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 938,
    cat_name: '女鞋',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 950,
        cat_name: '时尚女鞋',
        cat_pid: 938,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 952,
        cat_name: '品牌墙',
        cat_pid: 938,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 954,
    cat_name: '汽车生活',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 956,
        cat_name: '汽车整车',
        cat_pid: 954,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 958,
        cat_name: '养护配件',
        cat_pid: 954,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 975,
        cat_name: '清洁美容',
        cat_pid: 954,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 977,
        cat_name: '汽车电子',
        cat_pid: 954,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 984,
        cat_name: '汽车装饰',
        cat_pid: 954,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1000,
    cat_name: '运动户外',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1001,
        cat_name: '热门推荐',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1004,
        cat_name: '运动服饰',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1013,
        cat_name: '健身器材',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1027,
        cat_name: '骑行装备',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1031,
        cat_name: '体育休闲',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1047,
        cat_name: '户外鞋服',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1056,
        cat_name: '垂钓用品',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1061,
        cat_name: '运动鞋',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1073,
        cat_name: '户外装备',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1081,
        cat_name: '运动包/配件',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1084,
        cat_name: '品牌墙',
        cat_pid: 1000,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1100,
    cat_name: '美妆洗护',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1103,
        cat_name: '面部护理',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1109,
        cat_name: '美发护发',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1111,
        cat_name: '身体护理',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1132,
        cat_name: '口腔护理',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1133,
        cat_name: '男士护理',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1135,
        cat_name: '女性护理',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1138,
        cat_name: '香水彩妆',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1151,
        cat_name: '品牌墙',
        cat_pid: 1100,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1157,
    cat_name: '内衣配饰',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1162,
        cat_name: '文胸',
        cat_pid: 1157,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1169,
        cat_name: '睡衣',
        cat_pid: 1157,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1174,
        cat_name: '内裤',
        cat_pid: 1157,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1187,
        cat_name: '袜子',
        cat_pid: 1157,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1192,
        cat_name: '保暖内衣',
        cat_pid: 1157,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1202,
        cat_name: '配饰',
        cat_pid: 1157,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1208,
        cat_name: '品牌墙',
        cat_pid: 1157,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1218,
    cat_name: '童装玩具',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1225,
        cat_name: '婴幼玩具',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1228,
        cat_name: '户外玩具',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1231,
        cat_name: 'DIY玩具',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1246,
        cat_name: '遥控模型玩具',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1250,
        cat_name: '童装',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1259,
        cat_name: '童鞋',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1273,
        cat_name: '宝宝寝居',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1282,
        cat_name: '品牌墙',
        cat_pid: 1218,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1295,
    cat_name: '珠宝首饰',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1301,
        cat_name: '黄金珠宝',
        cat_pid: 1295,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1311,
        cat_name: '首饰配饰',
        cat_pid: 1295,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1315,
        cat_name: '邮币',
        cat_pid: 1295,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1327,
        cat_name: '品牌墙',
        cat_pid: 1295,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1335,
    cat_name: '智能设备',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1343,
        cat_name: '智能酷玩',
        cat_pid: 1335,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1350,
        cat_name: '潮流数码',
        cat_pid: 1335,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1352,
        cat_name: '智能家居',
        cat_pid: 1335,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1357,
        cat_name: '电子教育',
        cat_pid: 1335,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1367,
        cat_name: '品牌墙',
        cat_pid: 1335,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1369,
    cat_name: '钟表眼镜',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1375,
        cat_name: '精品钟表',
        cat_pid: 1369,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1383,
        cat_name: '眼镜',
        cat_pid: 1369,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1397,
        cat_name: '品牌墙',
        cat_pid: 1369,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1402,
    cat_name: '皮具箱包',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1410,
        cat_name: '功能箱包',
        cat_pid: 1402,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1419,
        cat_name: '时尚女包',
        cat_pid: 1402,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1420,
        cat_name: '男包皮具',
        cat_pid: 1402,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1428,
        cat_name: '品牌墙',
        cat_pid: 1402,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1441,
    cat_name: '邮币乐器',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1444,
        cat_name: '礼品',
        cat_pid: 1441,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1455,
        cat_name: '邮币',
        cat_pid: 1441,
        cat_level: 1,
        cat_deleted: false,
      },
      {
        cat_id: 1464,
        cat_name: '乐器',
        cat_pid: 1441,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
  {
    cat_id: 1480,
    cat_name: '其他',
    cat_pid: 0,
    cat_level: 0,
    cat_deleted: false,
    children: [
      {
        cat_id: 1482,
        cat_name: '热门关键词',
        cat_pid: 1480,
        cat_level: 1,
        cat_deleted: false,
      },
    ],
  },
]

export default {
  /**
   *获取分类列表
   *需要携带参数 ,page,limt(分页大小)
   * @param cateName,page,limit
   * @return {{code:number,count:number,data:*[]}}
   **/
  getCate: (config) => {
    const { cat_level, page = 1, pagesize = 20 } = param2Obj(config.url)
    const mockList = cateList.filter((cate) => {
      if (cat_level && cate.cat_level.indexOf(cat_level) === -1) return false
      return true
    })
    const pageList = mockList.filter((item, index) => index < pagesize * page && index >= pagesize * (page - 1))
    return {
      code: 200,
      count: mockList.length,
      data: pageList,
      meta: {
        msg: '获取成功',
      },
    }
  },
  /* 
  添加分类
 @param , cat_name cat_pid  cat_level
   * @return {{code:number,count:number,data:*[]}}
  */
  addCate: (config) => {
    const { cat_pid, cat_level, cat_name } = JSON.parse(config.body)
    addChild(cateList, cat_pid, cat_level)
    function addChild(list, cat_pid, cat_level) {
      //找到选中的父级元素 cat_level  cat_pid
      list.some((item) => {
        if (item.cat_level === cat_level && item.cat_id === cat_pid) {
          console.log(item)
          var newcate = { cat_id: Mock.Random.guid(), cat_name: cat_name, cat_pid: item.cat_id, cat_level: cat_level + 1, cat_deleted: false }
          if (item.children) item.children.push(newcate)
          else {
            item.children = []
            item.children.push(newcate)
          }
        }
        if (item.children instanceof Array && item.children.length > 0) {
          let text = addChild(item.children, cat_pid, cat_level)
          if (text) return true
        }
      })
    }
    return {
      code: 201,
      data: {
        message: '添加成功',
      },
    }
  },
  //获取父级分类
  getParent: (config) => {
    //深拷贝cateList
    var arrDeepCopy = function (source) {
      var sourceCopy = source instanceof Array ? [] : {}
      for (var item in source) {
        sourceCopy[item] = typeof source[item] === 'object' ? arrDeepCopy(source[item]) : source[item]
      }
      return sourceCopy
    }
    var list = arrDeepCopy(cateList)
    //去掉层级cat_level=2的元素
    // var list = cateList
    var parentTree = filterTree(list)
    function filterTree(list) {
      var newTree = list.filter((x) => x.cat_level !== 2)
      newTree.forEach((x) => x.children && (x.children = filterTree(x.children)))
      return newTree
    }
    //删除空数组
    var result = deleteChildren(parentTree)
    function deleteChildren(arr) {
      let childs = arr
      for (let i = childs.length; i--; i > 0) {
        if (childs[i].children) {
          if (childs[i].children.length) {
            deleteChildren(childs[i].children)
          } else {
            delete childs[i].children
          }
        }
      }
      return arr
    }
    return {
      code: 200,
      data: result,
      message: '获取父级前两级数据成功',
    }
  },
  /*
  修改分类
  @param id,cateName
  @return {{code: number, data: {message: string}}}
  */
  editCate: (config) => {
    const { cat_id, cat_name } = JSON.parse(config.body)
    recursionGet(cateList, cat_id, cat_name)
    function recursionGet(cateList, cate_id, cat_name) {
      cateList.some((u) => {
        if (u.cat_id === cat_id) {
          u.cat_name = cat_name
          return true
        }
        if (u.children instanceof Array && u.children.length > 0) {
          let text = recursionGet(u.children, cate_id, cat_name)
          if (text) return true
        }
      })
    }
    return {
      code: 201,
      data: {
        message: '修改成功',
      },
    }
  },
  /* 
  删除分类
  @param id
  @return {{code: number, data: {message: string}}}
  */
  deleteCate: (config) => {
    const cat_id = config.body
    cateList = filterTree(cateList, cat_id)
    function filterTree(cateList, cat_id) {
      var newTree = cateList.filter((x) => x.cat_id !== cat_id)
      newTree.forEach((x) => x.children && (x.children = filterTree(x.children, cat_id)))
      return newTree
    }
    return {
      code: 200,
      message: '删除成功',
    }
  },
}
